<template>
    <d2-container type="card">
        <header>
            <el-form :inline="true" :model="selectFrom" class="demo-form-inline" size="mini">
                <el-form-item label="流水类型">
                    <el-input v-model="selectFrom.type" placeholder="流水类型"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary">查询</el-button>
                </el-form-item>
            </el-form>
        </header>
        <footer>
            <el-table :data="tableData" border style="width: 100%" size="mini" :height="height">
                <el-table-column prop="id" label="金额流水ID" align="center">
                </el-table-column>
                <el-table-column label="流水类型" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.type == 0">订单</div>
                        <div v-if="scope.row.type == 1">储蓄</div>
                        <div v-if="scope.row.type == 2">提现</div>
                        <div v-if="scope.row.type == 3">返利</div>
                        <div v-if="scope.row.type == 4">成为分销商</div>
                    </template>
                </el-table-column>
                <el-table-column label="用户名称" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.userInfo">{{ scope.row.userInfo.name }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="骑手" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.deliveryInfo">{{ scope.row.deliveryInfo.name }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="店铺" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.shopInfo">{{ scope.row.shopInfo.name }}</div>
                    </template>
                </el-table-column>
                <el-table-column label="流入方向" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.inflowDirection == 0">流入</div>
                        <div v-if="scope.row.inflowDirection == 1">流出</div>
                    </template>
                </el-table-column>
                <el-table-column label="流入方式" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.inflowWay == 0">支付</div>
                        <div v-if="scope.row.inflowWay == 1">积分</div>
                    </template>
                </el-table-column>
                <el-table-column prop="orderId" label="订单ID" align="center">
                </el-table-column>
                <el-table-column prop="money" label="金额" align="center">
                </el-table-column>
                <el-table-column prop="integral" label="积分" align="center">
                </el-table-column>
                <el-table-column label="状态" align="center">
                    <template slot-scope="scope">
                        <div v-if="scope.row.state == 0">未完成</div>
                        <div v-if="scope.row.state == 1">已完成</div>
                    </template>
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间" align="center">
                </el-table-column>
            </el-table>
            <div class="block" style="text-align:center">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page"
                    :page-sizes="[5, 10, 15, 20]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>
        </footer>
    </d2-container>
</template>
  
<script>
import { getFlowMoney } from "@/api/modules/flow_money.js"
export default {
    name: 'FlowMoney',
    data() {
        return {
            selectFrom: {},//搜索栏
            tableData: [],//表格数据
            page: 1,
            limit: 10,
            total: 0,
            height: window.innerHeight - 250, //表格高度
        }
    },
    mounted() {
        this.getFlowMoneyData();
        //-------------------------表格响应----------------//
        this.createHeight();
        //当页面发生变化时，表格高度固定
        window.onresize = () => {
            return (() => {
                this.$nextTick(() => {
                    this.createHeight();
                });
            })();
        };
    },
    methods: {
        //获取金额流水
        getFlowMoneyData(){
            this.selectFrom.page = this.page;
            this.selectFrom.limit = this.limit;
            getFlowMoney(this.selectFrom).then(res=>{
                this.tableData = res.dataList;
                this.total = res.total;
            })
        },
        handleSizeChange(val) {
            this.limit = val;
            this.getFlowMoneyData();
        },
        handleCurrentChange(val) {
            this.page = val;
            this.getFlowMoneyData();
        },
        //---------------自动变更表格高度------------------//
        createHeight() {
            this.height = window.innerHeight - 250;
        }
    }
}
</script>
  